<?php

/*----------------------------------------------+
|  MaxForum					|
|  ===========================================	|
|  By Majd Almontaser				|
|  Released under the License GNU v3.0		|
|  http://www.Max4Dev.com			|
|  ===========================================	|
|  Ttmtt Team - http://www.liioiil.com		|
+-----------------------------------------------*/

if (!defined('MAX_ON')){
	echo "<h1>ACCESS DENIED</h1>You cannot access this file directly.";
	exit();
}

#---------------------------
# Startup
#---------------------------

	$id = (int) $_GET['id'];

	# Load star rater
	require 'rater/_drawrating.php';

	# Starting hooks
	$Gallery->template('pages/gallery/view-image.template.php')->hook('start', 1);

#--------------------------------
# Get image information
#--------------------------------

	$query = mysql_query('
		SELECT
			img.*, abm.id as album_id, abm.name as album_name, m.id as user_id, m.name as user_name
		
		FROM
			' . $db_prefix . 'gallery_images img, ' . $db_prefix . 'gallery_albums abm, ' . $db_prefix . 'members m
			
		WHERE	
			img.id = ' . $id . ' AND
			img.album = abm.id AND
			img.user = m.id
		
		LIMIT 1
	');
	
	$row = mysql_fetch_assoc($query);
	
		$row = array_map('strip_slashes', $row);
	
		$row['image']						= 'uploads/gallery/images/' . $row['image'];
		$lang['view_image_uploaded_on']		= sprintf($lang['view_image_uploaded_on'], format_date($row['time']), member_link($row['user_id'], 0));
		
		#-------------------------------------------------------------------
		# Work out resized dimensions so it fits on the page
		#-------------------------------------------------------------------
		
			$max					= 420;
			list($width, $height)	= getimagesize($row['image']);
			
			if ($width > $max)
			{
				$scale = $width / $max;
				
				$width	= $width / $scale;
				$height	= $height / $scale;
			}

#-----------------------------
# Get image comments
#-----------------------------

	$query = mysql_query('
		SELECT
			c.comment, c.time, m.id, m.name
			
		FROM
			' . $db_prefix . 'gallery_images_comments c, ' . $db_prefix . 'members m
			
		WHERE
			c.image = ' . $id . ' AND
			c.user = m.id
			
		ORDER BY
			c.time DESC
	') or die (mysql_error());
	
	$comments = mysql_num_rows($query);
	
		$lang['view_image_comments']	= sprintf($lang['view_image_comments'], $comments);
	
	$Gallery->hook('2');
	
	while ($row = mysql_fetch_assoc($query))
	{
		$row['comment'] = iconv('UTF-8', 'CP1256', $row['comment']);
		$row['comment']	= strip_slashes($row['comment']);
		$var1 = member_link($row['id'], 0);
		$var2 = format_date($row['time']);
		$by = sprintf($lang['view_image_comments_by'], $var1, $var2);
		$Gallery->hook('3');
	}
	
$Gallery->hook('4', 'end');
?>
